﻿using FineUICore;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using SysFrame.BP;
using SysFrame.Message;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;

namespace FineUIAPPTest.Areas.system.Controllers
{
    [Area("system")]
    public class System1Controller : Controller
    {
        public IActionResult Index()
        {
            InitPage(null, null);
            return View();
        }


        /// <summary>
        /// 初始化页面
        /// </summary>
        /// <param name="msq">条件</param>
        /// <param name="fields">字段</param>
        private void InitPage(MsQuery msq, JArray fields) {
            if (msq == null) {
                msq = new MsQuery();
            }
            msq.strquery += " and 1=1 and system_1_20!='admin'";
            DataTable dt = ((DataSet)new BLLsystem_1().Getsystem_1ByQuery(msq).data).Tables[0];

            //是否回发
            if (UIHelper.IsFineUIAjaxPostBack())
            {
                var Grid1 = UIHelper.Grid("Grid1");
                if (fields != null)
                {
                    Grid1.DataSource(dt, fields);
                }
            }
            else {
                ViewBag.griddata = dt;
            }
        }

        [HttpPost]
        public IActionResult btnSearch_Click(IFormCollection values) 
        {
            JObject obj = JObject.FromObject(values.ToDictionary(x => x.Key, x => x.Value.ToString()));
            Mssystem_1 sys1 = Mssystem_1.parse(obj);
            return UIHelper.Result();
        }

        public IActionResult sys1Edit()
        {
            return View();
        }
    }
}
